import { ConfigContext, ExpoConfig } from "@expo/config";

const IS_DEV = process.env.APP_VARIANT === "development";
const IS_PREVIEW = process.env.APP_VARIANT === "preview";

const getUniqueIdentifier = (isIos: boolean) => {
  let identifier = isIos
    ? "com.tommi.pickfun.tool"
    : "com.bennysoft.pickfuntool";
  if (IS_DEV) {
    identifier += ".dev";
  }

  if (IS_PREVIEW) {
    identifier += ".preview";
  }

  return identifier;
};

const getAppName = () => {
  if (IS_DEV) {
    return "PickFunTools(Dev)";
  }

  if (IS_PREVIEW) {
    return "PickFunTools(Preview)";
  }

  return "PickFun Tools";
};

export default ({ config }: ConfigContext): ExpoConfig => ({
  ...config,
  name: getAppName(),
  slug: "pickfun-tools",
  version: "1.0.8",
  orientation: "portrait",
  icon: "./assets/images/icon.png",
  scheme: "myapp",
  userInterfaceStyle: "automatic",
  newArchEnabled: true,
  ios: {
    supportsTablet: false,
    bundleIdentifier: getUniqueIdentifier(true),
    buildNumber: "2",
    entitlements: {
      "aps-environment": "development",
    },
    infoPlist: {
      ITSAppUsesNonExemptEncryption: false,
    },
    icon: "./assets/images/iosicon.icon",
  },
  android: {
    adaptiveIcon: {
      foregroundImage: "./assets/images/adaptive-icon.png",
      monochromeImage: "./assets/images/adaptive-icon.png",
      backgroundColor: "#ffffff",
    },
    package: getUniqueIdentifier(false),

    permissions: [
      "android.permission.ACCESS_FINE_LOCATION",
      "android.permission.CAMERA",
      "android.permission.RECORD_AUDIO",
      "android.permission.READ_EXTERNAL_STORAGE",
      "android.permission.WRITE_EXTERNAL_STORAGE",
      "android.permission.ACCESS_MEDIA_LOCATION",
      "android.permission.MODIFY_AUDIO_SETTINGS",
    ],
  },
  web: {
    bundler: "metro",
    output: "static",
    favicon: "./assets/images/favicon.png",
  },
  plugins: [
    "expo-router",
    "expo-asset",
    [
      "react-native-permissions",
      {
        iosPermissions: ["Camera", "Microphone"],
      },
    ],
    [
      "expo-camera",
      {
        cameraPermission:
          "$(PRODUCT_NAME)需要访问您的摄像头，以便您能够扫描识别二维码。没有此权限，您将无法扫描识别二维码。",
        microphonePermission: "Allow $(PRODUCT_NAME) to access your microphone",
        recordAudioAndroid: true,
      },
    ],
    [
      "expo-image-picker",
      {
        photosPermission:
          "The app accesses your photos to let you share them with your friends.",
      },
    ],
    "expo-font",
    [
      "expo-splash-screen",
      {
        image: "./assets/images/splash-icon-dark.png",
        imageWidth: 200,
        resizeMode: "contain",
        backgroundColor: "#ffffff",
        dark: {
          image: "./assets/images/splash-icon-light.png",
          backgroundColor: "#000000",
        },
      },
    ],
    [
      "react-native-edge-to-edge",
      {
        android: {
          parentTheme: "Default",
        },
      },
    ],
    [
      "expo-audio",
      {
        microphonePermission:
          "Allow $(PRODUCT_NAME) to access your microphone.",
      },
    ],
  ],
  experiments: {
    typedRoutes: true,
  },
  extra: {
    router: {
      origin: false,
    },
    eas: {
      projectId: "969abd68-38f0-41fc-bc8a-a5036a62a59f",
    },
  },
  owner: "bennyshen",
});
